package com.zxl.jdk8test;

import java.util.Comparator;

public class ComparatorTest {
    
    public static void main(String[] args) {
        Comparator<Person> comparator = (p1,p2) -> {
            int a = p1.getAge() - p2.getAge();
            System.out.println("年龄差距 ：" + a + "岁");
            if (p1.getAge() >= p2.getAge()) {
                return 1;
            }else{
                return -1;
            }
        };
        Person person1 = new Person("a", 22);
        Person person2 = new Person("b", 13);
        System.out.println(comparator.compare(person1, person2));
    }
}
